package com.zhs.study.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.study.dao.RoleDao;
import com.zhs.study.dto.RoleDto;
import com.zhs.study.model.Role;
import com.zhs.study.service.IRoleService;
import com.zhs.study.common.Enum.R;
import com.zhs.study.common.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;


/**
 *
 * @author
 * @since 2023-12-19
 */
@Service
@Slf4j
public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements IRoleService {

    @Resource
    private RoleDao roleDao;

    @Override
    public R addOrUpdate(RoleDto roleDto) {
        if (BeanUtil.isEmpty(roleDto)) throw new ServiceException("数据不能为空");
        Role role = new Role();
        BeanUtil.copyProperties(roleDto,role);
        if (roleDto.getId() == null){
            roleDao.insert(role);
            return R.ok("数据插入成功");
        }else {
            roleDao.updateById(role);
            return R.ok("数据更新成功");
        }
    }
}
